
/*
 页面父类基础界面
 */
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:xsdk_flutter/xsdk/framework/bean/x_bean_menu.dart';
import 'package:xsdk_flutter/xsdk/framework/page/x_page_state_tabbar_tabview.dart';

/*
导航界面(利用自带TabBar实现)
 */
abstract class XPageGuideState extends XPageTabBarTabViewState{

  Timer? _timer;
  bool isAutoChangeGuideItem;

  //加载引导页标签
  List<XBeanMenuItem> guideItems=[];

  int _currentTabIndex=0;

  XPageGuideState(
      {
        this.isAutoChangeGuideItem=true,
      }
      );

  @override
  void onCreate() {
    super.onCreate();

    //延迟切换
    if(isAutoChangeGuideItem){
      _timer??=Timer.periodic(const Duration(milliseconds: 3000), (Timer timer){
        changeNextTab();
      });
    }

  }


  @override
  void notifyTabControllerChangeCallback(int tabIndex){

    //实测会重复返回,动画导致???,过滤处理
    //XLogUtils.printLog('${tabController?.index}');
    if(tabIndex!=_currentTabIndex){
      _currentTabIndex=tabIndex;
      _timer?.cancel();
      _timer=null;
      _timer??=Timer.periodic(const Duration(milliseconds: 3000), (Timer timer){
        changeNextTab();
      });
    }

  }


  //显示底部指示条
  @override
  bool getIsShowBottomTabPageSelector(){
    return true;
  }

  @override
  void onStart() {

  }

  @override
  Future<void> updateData({int pageIndex = 1}) async {

    List<String> tempGuideitems=getGuideItems();

    for(String item in tempGuideitems){
      guideItems.add(XBeanMenuItem(text: item));
    }

    updateXTabBar(
        items:guideItems
    );

  }


  @override
  void onDestroy() {
    super.onDestroy();
    _timer?.cancel();
    _timer = null;
  }

//引导页标签名
  @required
  List<String> getGuideItems();



}